// pages/wholeMine/wholeMine.js
var app=getApp();
var model = require('../../utils/model/model.js');   
var util = require('../../utils/util.js');  
Page({

  /**
   * 页面的初始数据
   */
  data: {
    httpApiImg: app.globalData.httpApiImg,
    imgUrl: app.globalData.imageUrl,
    userInfo: '',
    serviceData:[
      { txt: '我的关注', imgurl: app.globalData.imageUrl + "my_my_attention@2x.png", url: '/pages/myAttention/myAttention' },
      { txt: '我的收藏', imgurl: app.globalData.imageUrl + "my_my_ collection@2x.png", url: '/pages/myCollection/myCollection' },
      { txt: '我的报名', imgurl: app.globalData.imageUrl + "my_my_registration@2x.png",url:'/pages/myRegistration/myRegistration'},
      { txt: '我的活动', imgurl: app.globalData.imageUrl + "my_my_activity@2x.png", url: '/pages/myRegistration/myRegistration?isMine=true' },
      { txt: '我的商家', imgurl: app.globalData.imageUrl + "my_my_merchants@2x.png", url: '/pages/shopIndex/shopIndex?whole=1' },
      { txt: '我的行程', imgurl: app.globalData.imageUrl + "my_my_schedule@2x.png", url: '/pages/personForCar/personForCar?isWholeMine=true' },
      { txt: '我的招聘', imgurl: app.globalData.imageUrl + "my_my_recruitment@2x.png", url: '/pages/recruitMine/recruitMine?page=wholeMine&myIsRcruit=true' },
      { txt: '我的求职', imgurl: app.globalData.imageUrl + "my_my_apply@2x.png", url: '/pages/recruitMine/recruitMine?page=wholeMine&myIsRcruit=false' },
      { txt: '我的相亲', imgurl: app.globalData.imageUrl + "my_my_blind_date@2x.png", url: '/pages/blindMine/blindMine?page=wholeMine' },
      { txt: '我的房源', imgurl: app.globalData.imageUrl + "ic_my_housing@2x.png", url: '/pages/houseSeller/houseSeller?page=wholeMine&flag=2'},
      { txt: '我的二手', imgurl: app.globalData.imageUrl + "my_my_second_hand@2x.png", url: '/pages/secondHand/secondHand?page=wholeMine' },
      { txt: '我的打赏', imgurl: app.globalData.imageUrl + "reward@2x.png", url: '/pages/myReward/myReward' },
      { txt: '完善资料', imgurl: app.globalData.imageUrl + "my_perfect_data@2x.png", url:"/pages/perfectInfo/perfectInfo"},
    ],
    userInfo: '',
    isSign:false,
    showSignSucess:false,
    modelData: {
      showModal: false,
      signle:true,
      signleBtnTxt:'OK',
      content: '关注港悦生活公众号可享受 相亲、求职招聘、二手闲置、 房屋租赁等服务',
      // confirmCallback: 'confirmCallback'
    },
    bottabData: app.globalData.bottabData,
    showRelease: false,
    fbList: app.globalData.fbList,
    isShop:'',
    isLogout: true,
    isRead: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      isOut: wx.getStorageSync("isOut"),
      isShop: wx.getStorageSync('isShop'),     
      userInfo: JSON.parse(wx.getStorageSync('userInfo')),
      ['bottabData[3].current']: true
    })
    wx.setStorageSync('userInfo', JSON.stringify(this.data.userInfo));
    model.init.apply(this, ['modelData']);
    this.getIsSign();
    
  },
  getIsRead: function () {
    var _this = this;
    wx.request({
      url: app.globalData.httpApiCar + 'tGySystemMessage/noneRead',
      data: {
        toUserId: this.data.userInfo.id
      },
      method: 'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 默认值
      },
      success: function (res) {
        if (res.data.success) {
          _this.setData({
            isRead: res.data.data
          })
        }
      }
    })
  },
  releaseTap: function (e) {
    var item = e.currentTarget.dataset.item;
    if (item.type == 1 || item.type == 4) {
      if (this.data.userInfo.brandCar) {
        wx.navigateTo({
          url: item.url
        })
      } else {
        wx.showModal({
          title: '提示',
          content: '你还没有完善车辆信息，请先去完善',
          success: function (res) {
            if (res.confirm) {
              wx.navigateTo({
                url: "/pages/perfectInfo/perfectInfo"
              })
            } else {//取消
            }
          }
        })
      }
    } else {
      if (item.url) {
        wx.navigateTo({
          url: item.url
        })
      }
      else {
        if (this.data.isShop == 0) {
          wx.navigateTo({
            url: '/pages/seller/seller'
          })
        }
        else if (this.data.isShop == 1) {
          let isOut = wx.getStorageSync("isOut");
          if (isOut == 1) {
            wx.showModal({
              title: '提示',
              content: '您的店铺已到期，请续费',
              showCancel: false,
              success: function (res) {
                if (res.confirm) {
                  wx.navigateTo({
                    url: '/pages/shopIndex/shopIndex?whole=1'
                  })
                }
              }
            })
          }
          else {
            wx.navigateTo({
              url: '/pages/sjwppublish/sjwppublish'
            })
          }
        }
        else if (this.data.isShop == 2) {
          wx.showToast({
            title: '店铺正在审核中，请稍后发布商品',
            icon: 'none',
            duration: 2000
          })
        }
      }
    }
  },
  bindOut: function(){
    wx.showModal({
      title: '提示',
      content: '您的店铺已到期，请续费',
      showCancel: false,
      success: function (res) {
        if (res.confirm) {
          wx.navigateTo({
            url: '/pages/shopIndex/shopIndex?whole=1'
          })
        }
      }
    })
  },
  // 进入我的订单页面
  // openPage: function () {
  //   wx.navigateTo({
  //     url: '/pages/myOrder/myOrder',
  //   })
  // },
  switchBotab: function (e) {
    if (e.currentTarget.dataset.url) {
      if (e.currentTarget.dataset.index != 3) {
        wx.redirectTo({
          url: e.currentTarget.dataset.url
        })
      }
    } else {
      this.setData({ showRelease: true })
    }
  },
  hideRelease: function (e) {
    this.setData({ showRelease: false })
  },
  getIsSign: function (e) {
    var _this = this;
    wx.request({
      url: app.globalData.httpApiCar + 'tGyUserSign/isSign', //仅为示例，并非真实的接口地址
      data: {
        userId: this.data.userInfo.id
      },
      success: function (res) {
        if (res.data.success){
          _this.setData({
            isSign: res.data.data
          })
        }  
      }
    })
  },
  changeSign:function(e){//签到
    // var flag=e.currentTarget.dataset.value=="true"?true:false;
    if (!this.data.isSign){
      this.setSign();
    }
  },
  setSign: function () {
    var _this = this;
    wx.request({
      url: app.globalData.httpApiCar + 'tGyUserSign/sign',
      data: {
        userId: this.data.userInfo.id
      },
      method: 'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 默认值
      },
      success: function (res) {
        if (res.data.success){
          _this.setData({
            showSignSucess: true,
            isSign: true
          })
        }
      }
    })
  },
  showSignModel:function(e){
    this.setData({
      showSignSucess: false
    })
  },
  logoutFunc: function(){
    this.setData({
      isLogout: false
    })
  },
  cancel: function(){
    this.setData({
      isLogout: true
    })
  },
  confirm: function(){
    wx.removeStorageSync("userInfo");
    wx.removeStorageSync("iden");
    wx.removeStorageSync("isShop");
    this.cancel();
    wx.redirectTo({
      url: '/pages/login/login',
    })
  },
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getIsRead();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})